package eg.com.itiga.repositoryimpl.company;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import eg.com.itiga.domain.Branch;
import eg.com.itiga.domain.RegCompany;
import eg.com.itiga.repository.company.RegCompanyDao;
import eg.com.itiga.repository.exception.DataException;
import eg.com.itiga.repositoryimpl.base.BaseDaoImpl;
import eg.com.itiga.repositoryimpl.base.HibernateUtil;

public class RegCompanyDaoImpl extends BaseDaoImpl implements RegCompanyDao 
{
	/**
	 * @Author Mostafa 
	 * get a list of Company Requests
	 * @return List<RegCompany>
	 */
	public List<RegCompany> getCompanyRequests() throws DataException 
	{
		List<RegCompany> unRegisteredCompanies = null;
		
		Session session = HibernateUtil.getCurrentSession();
		try 
		{			
			Criteria criteria = session.createCriteria(RegCompany.class);
			criteria.add(Restrictions.eq("CState", RegCompany.REQUESTED));

			unRegisteredCompanies = criteria.list();
			
		} catch (HibernateException e) 
		{
			e.printStackTrace();
			throw new DataException("Data Exception");
		}
		
		return unRegisteredCompanies;
	}

	/**
	 * @Author Bola
	 * Add company registration request
	 */
	public void requestRegistration(RegCompany regCompany) throws DataException {
		Session session = HibernateUtil.getCurrentSession();
		try {
			regCompany.setIsRegIsApproved(false);
			regCompany.setCState(RegCompany.REQUESTED);
			session.save(regCompany);		
			
		} catch (HibernateException e) {
			e.printStackTrace();
			throw new DataException("Data Exception");
		}
		
	}

	
	
}
